package com.qiqu.controller;

import com.qiqu.commen.Const;
import com.qiqu.entity.Comments;
import com.qiqu.service.CommentsService;
import com.qiqu.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author Administrator
 */
@RestController
@RequestMapping("comments")
@Api(value = "评论相关接口",tags = {"评论相关接口controller"})
public class CommentsController {
    @Resource
    private CommentsService commentsService;

    //添加评论
    @ApiOperation(value = "添加评论--fk",notes = "添加评论")
    @PostMapping("/addComment")
    public JSONResult addComment(@RequestBody Comments comments) {
        return JSONResult.ok(commentsService.addComments(comments));
    }

    //删除评论
    @ApiOperation(value = "删除评论--fk",notes = "删除评论")
    @ApiImplicitParam(name="commentId",value = "评论Id",required = true,dataType = "string",paramType = "query")
    @PostMapping("/deleteComment")
    public JSONResult addComment(String commentId) {
        return  JSONResult.ok(commentsService.deleteById(commentId));
    }
    //统计总评论数
    @ApiOperation(value = "统计总评论数--fk",notes = "统计总评论数")
    @PostMapping("/totalComments")
    public JSONResult totalComments() {
        return JSONResult.ok(commentsService.totalComments());
    }


    //统计单个文章评论数
    @ApiOperation(value = "统计单个文章评论数--fk",notes = "统计单个文章评论数")
    @ApiImplicitParam(name="articleId",value = "文章Id",required = true,dataType = "string",paramType = "query")
    @GetMapping("/articleComments")
    public JSONResult articleComments(String articleId) {
        return JSONResult.ok(commentsService.articleComments(articleId));
    }


    //获取文章评论
    @ApiOperation(value = "获取文章评论--fk",notes = "获取文章评论")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="page",value = "页码",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name="articleId",value = "文章Id",required = true,dataType = "string",paramType = "query")
    })
    @PostMapping("/getComments")
    public JSONResult getComments(String articleId,Integer page) {
        if(page==null){
            page=1;
        }
        return  JSONResult.ok(commentsService.getComments(articleId,page, Const.PAGE_SIZE));
    }

}